/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package net.cjb.malacma.rssfeed.servlet;

/**
 *
 * @author malacma
 */
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author morettinho
 * @Mind Map Luis Augusto Machado Moretto
 * @EMAIL:malacma@gmail.com
 * @URL:http://malacma.cjb.net
 *
 * Please leave this comment!
 *
 * @DATE: 18/12/2007
 *
 *
 */
class ActionInvoke {

    /**
     * Invoke a Method based on the class and method name defined
     * @param nmClass
     * @param nmMethod
     * @param params
     * @throws java.lang.ClassNotFoundException
     * @throws java.lang.InstantiationException
     * @throws java.lang.IllegalAccessException
     * @throws java.lang.IllegalArgumentException
     * @throws java.lang.reflect.InvocationTargetException
     */
    public static void execute(String nmClass, String nmMethod,HttpServletRequest request, HttpServletResponse response) throws ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException ,IOException{
        Class c = Class.forName(nmClass);

        Object o = c.newInstance();

        Method[] m = c.getDeclaredMethods();

        for (Method m1 : m) {
            if (m1.getName().toString().equalsIgnoreCase(nmMethod)) {
                m1.invoke(o, response.getWriter() , request, response);
                break;
            }
            m1 = null;
        }

        //Destroy
        nmClass = null;
        nmMethod = null;
        c = null;
        o = null;
        m = null;
    }

}